<template>
	<view class="padding-sm">
		<view class="u-flex " style="border-bottom: 1px solid #f2f3f6;padding: 10rpx 0;" v-for="(item,index) in list"
			:key="index" @click="go_message(item.id,item.operate_type,item.state)">
			<view class="read" v-if="item.state==1"></view>
			<view class="noRead" v-else></view>
			<view class="margin-left-lg" style="line-height: 33rpx; font-size: 28rpx;font-weight: 400;">
				{{item.message}}
			</view>
		</view>
		<!-- 确认弹框 -->
		<u-modal :show="shanchushow" style="text-align: center;" confirmText="同意" cancelText="不同意" showCancelButton
			cancelColor="#1D2129" confirmColor="#7D81A9" @cancel="operate_message(0)" close @confirm="operate_message(1)">
			是否同意?
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				shanchushow: false,
				id: '',
				operate_type: ''
			};
		},
		async onShow() {
			const res = await uni.$http.post('user/get_user_message_list')
			this.list = res.data.data
		},
		methods: {
			go_message(id,operate_type,state) {
				if(state == 1) {
					return;
				}
				
				this.id = id;
				this.operate_type = operate_type;
				
				if(operate_type == 1) {
					this.operate_message_type();
				}
				if(operate_type == 2) {
					this.message();
				}
			},
			message() {
				this.shanchushow = true;
			},
			async operate_message(type) {
				const {
				  data: res
				} = await uni.$http.post('user/operate_message', {
					id: this.id,
					operate_result: type
				})

				this.shanchushow = false;
				if (res.code != 1) {
					this.toast.msg(res.msg)
					return
				}

				const result = await uni.$http.post('user/get_user_message_list')
				this.list = result.data.data
			},
			async operate_message_type() {
				const {
				  data: res
				} = await uni.$http.post('user/operate_message', {
					id: this.id
				})
			
				this.shanchushow = false;
				if (res.code != 1) {
					this.toast.msg(res.msg)
					return
				}
			
				const result = await uni.$http.post('user/get_user_message_list')
				this.list = result.data.data
			}
		},

	};
</script>
<style lang="scss">
	.read {
		width: 8rpx;
		height: 8rpx;
		background: rgba(125, 129, 169, 0.4);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		opacity: 1;
	}

	.noRead {
		width: 8rpx;
		height: 8rpx;
		background: #E64F5E;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		opacity: 1;
	}
</style>